/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NLPAnnotator.java
 *
 * Created on Feb 28, 2011, 10:41:46 AM
 */

package annotate.gui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.io.File;
import javax.swing.Icon;
import javax.swing.JFileChooser;

/**
 *
 * @author Chris
 */
public class NLPAnnotator extends javax.swing.JPanel {

    /**follows three icons are used to indicates the status of running button*/
    private Icon disabled = null;
    private Icon enabled = null;
    private Icon mouseon = null;
    /**point to parent frame*/
    protected userInterface.GUI __gui;

    /**latest accessed folder in eHOST.*/
    private File recentlyOpennedFolder = null;



    /** Creates new form NLPAnnotator */
    public NLPAnnotator(userInterface.GUI _gui) {
        this.__gui = _gui;
        initComponents();

        loadingRes();
        ComponentSetting();

        try{
            if(recentlyOpennedFolder==null)
            {
                File currentproject=env.Parameters.WorkSpace.CurrentProject;
                if((currentproject!=null)&&(currentproject.exists())&&(currentproject.isDirectory()))
                {
                    recentlyOpennedFolder = new File(currentproject.getAbsolutePath() + File.separator + "NLPResults"+File.separator);
                    
                    if(!recentlyOpennedFolder.exists())
                        recentlyOpennedFolder.mkdirs();

                    env.Parameters.NLPAssistant.outputpath = recentlyOpennedFolder.getAbsolutePath();
                }
            }
        }catch(Exception ex){
            
        }
        
    }



    private void loadingRes(){
        //follows three icons are used to indicates the status of running button
        disabled = new javax.swing.ImageIcon(getClass().getResource("/annotate/gui/starts_disabled.jpg"));
        enabled = new javax.swing.ImageIcon(getClass().getResource("/annotate/gui/starts.jpg"));
        mouseon = new javax.swing.ImageIcon(getClass().getResource("/annotate/gui/starts_mouseon.jpg"));
    }

    private void ComponentSetting(){
        jCheckBox_Dates.setEnabled(jCheckBox_PreDefiined.isSelected());
        jCheckBox_SSN.setEnabled(jCheckBox_PreDefiined.isSelected());



    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel_top = new javax.swing.JPanel();
        jPanel_firstlevel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel8 = new javax.swing.JPanel();
        jPanel_secondlevel = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jCheckBox_Dates = new javax.swing.JCheckBox();
        jCheckBox_SSN = new javax.swing.JCheckBox();
        jCheckBox_PreDefiined = new javax.swing.JCheckBox();
        jLabel2 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jCheckBox_concept = new javax.swing.JCheckBox();
        jLabel3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jPanel13 = new javax.swing.JPanel();
        jRadioButton_nlp_normal = new javax.swing.JRadioButton();
        jRadioButton_nlp_quick = new javax.swing.JRadioButton();
        jPanel3 = new javax.swing.JPanel();
        jCheckBox_CustomRegex = new javax.swing.JCheckBox();
        jPanel5 = new javax.swing.JPanel();
        jPanel_thirdlevel = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jCheckBox_Experiencer = new javax.swing.JCheckBox();
        jCheckBox_Temporality = new javax.swing.JCheckBox();
        jCheckBox_negation = new javax.swing.JCheckBox();
        jPanel9 = new javax.swing.JPanel();
        jPanel12 = new javax.swing.JPanel();
        jPanel10 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel11 = new javax.swing.JPanel();

        setBackground(new java.awt.Color(254, 255, 255));
        setLayout(new java.awt.BorderLayout());

        jPanel_top.setLayout(new java.awt.BorderLayout());

        jPanel_firstlevel.setBackground(new java.awt.Color(255, 254, 255));
        jPanel_firstlevel.setBorder(javax.swing.BorderFactory.createMatteBorder(12, 1, 1, 1, new java.awt.Color(255, 254, 255)));
        jPanel_firstlevel.setLayout(new java.awt.BorderLayout());

        jLabel1.setBackground(new java.awt.Color(255, 254, 255));
        jLabel1.setFont(new java.awt.Font("Arial", 0, 10)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/annotate/gui/startpoint.jpg"))); // NOI18N
        jLabel1.setText("Welcome");
        jLabel1.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jLabel1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel_firstlevel.add(jLabel1, java.awt.BorderLayout.NORTH);

        jPanel8.setBackground(new java.awt.Color(255, 254, 255));

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 3127, Short.MAX_VALUE)
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 54, Short.MAX_VALUE)
        );

        jPanel_firstlevel.add(jPanel8, java.awt.BorderLayout.CENTER);

        jPanel_top.add(jPanel_firstlevel, java.awt.BorderLayout.PAGE_START);

        jPanel_secondlevel.setBackground(new java.awt.Color(254, 254, 255));
        jPanel_secondlevel.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 18, 1, 18, new java.awt.Color(254, 254, 255)));
        jPanel_secondlevel.setLayout(new java.awt.GridLayout(1, 3, 12, 0));

        jPanel2.setBackground(new java.awt.Color(240, 240, 239));
        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153)));

        jCheckBox_Dates.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jCheckBox_Dates.setText("Date & Time");

        jCheckBox_SSN.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jCheckBox_SSN.setText("SSN");

        jCheckBox_PreDefiined.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jCheckBox_PreDefiined.setText("<html><b>Using custom regular expressions</b></html>");
        jCheckBox_PreDefiined.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_PreDefiinedActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Arial", 0, 10)); // NOI18N
        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/annotate/gui/oracle1.jpg"))); // NOI18N
        jLabel2.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153)));
        jLabel2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jLabel2.setVerifyInputWhenFocusTarget(false);
        jLabel2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jLabel2)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBox_SSN)
                            .addComponent(jCheckBox_Dates)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCheckBox_PreDefiined, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(769, 769, 769))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jCheckBox_PreDefiined, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jCheckBox_Dates)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCheckBox_SSN))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addComponent(jLabel2)))
                .addContainerGap(164, Short.MAX_VALUE))
        );

        jPanel_secondlevel.add(jPanel2);

        jPanel1.setBackground(new java.awt.Color(240, 240, 239));
        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153)));

        jCheckBox_concept.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jCheckBox_concept.setSelected(true);
        jCheckBox_concept.setText("<html>Searching<br><font color=\"gray\">Using existing<p>dictionaries</font></html>");
        jCheckBox_concept.setActionCommand("Concept and related relationship");
        jCheckBox_concept.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jCheckBox_concept.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_conceptActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Arial", 0, 10)); // NOI18N
        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/annotate/gui/search.png"))); // NOI18N
        jLabel3.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153)));
        jLabel3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jLabel3.setVerifyInputWhenFocusTarget(false);
        jLabel3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        jButton1.setText("Configure Dictionaries");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jPanel13.setBackground(new java.awt.Color(240, 240, 239));
        jPanel13.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 2, 2, 2, new java.awt.Color(204, 204, 255)));
        jPanel13.setLayout(new java.awt.GridLayout(1, 0));

        buttonGroup1.add(jRadioButton_nlp_normal);
        jRadioButton_nlp_normal.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jRadioButton_nlp_normal.setSelected(true);
        jRadioButton_nlp_normal.setText("<html><b>Normal Speed</b><div> (for small dictionary)</html>");
        jPanel13.add(jRadioButton_nlp_normal);

        buttonGroup1.add(jRadioButton_nlp_quick);
        jRadioButton_nlp_quick.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jRadioButton_nlp_quick.setText("<html><b>Quick Extraction</b><div> (for larger dictionary above 1 million records)</html>");
        jRadioButton_nlp_quick.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jRadioButton_nlp_quickStateChanged(evt);
            }
        });
        jRadioButton_nlp_quick.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton_nlp_quickActionPerformed(evt);
            }
        });
        jPanel13.add(jRadioButton_nlp_quick);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel13, javax.swing.GroupLayout.DEFAULT_SIZE, 1005, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jCheckBox_concept, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 831, Short.MAX_VALUE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 1009, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel3))
                    .addComponent(jCheckBox_concept, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(123, Short.MAX_VALUE))
        );

        jPanel_secondlevel.add(jPanel1);

        jPanel3.setBackground(new java.awt.Color(240, 240, 239));
        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153)));
        jPanel3.setInheritsPopupMenu(true);

        jCheckBox_CustomRegex.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        jCheckBox_CustomRegex.setText("<html><b>Search Terms<p>Using custom regular expressions</b></html>");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jCheckBox_CustomRegex, javax.swing.GroupLayout.DEFAULT_SIZE, 1009, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jCheckBox_CustomRegex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(228, Short.MAX_VALUE))
        );

        jPanel_secondlevel.add(jPanel3);

        jPanel_top.add(jPanel_secondlevel, java.awt.BorderLayout.CENTER);

        add(jPanel_top, java.awt.BorderLayout.NORTH);

        jPanel5.setBackground(new java.awt.Color(254, 255, 255));
        jPanel5.setLayout(new java.awt.BorderLayout());

        jPanel_thirdlevel.setBackground(new java.awt.Color(254, 254, 255));
        jPanel_thirdlevel.setBorder(javax.swing.BorderFactory.createMatteBorder(24, 18, 1, 18, new java.awt.Color(254, 254, 255)));
        jPanel_thirdlevel.setLayout(new java.awt.GridLayout(1, 3, 12, 0));

        jPanel6.setBackground(new java.awt.Color(255, 255, 254));

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1023, Short.MAX_VALUE)
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 150, Short.MAX_VALUE)
        );

        jPanel_thirdlevel.add(jPanel6);

        jPanel4.setBackground(new java.awt.Color(255, 255, 254));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1023, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 150, Short.MAX_VALUE)
        );

        jPanel_thirdlevel.add(jPanel4);

        jPanel7.setBackground(new java.awt.Color(240, 240, 239));
        jPanel7.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153)));
        jPanel7.setInheritsPopupMenu(true);

        jCheckBox_Experiencer.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jCheckBox_Experiencer.setText("<html>Experiencer<br><font color=\"gray\">Patient or others</font></html>");
        jCheckBox_Experiencer.setActionCommand("Concept and related relationship");
        jCheckBox_Experiencer.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jCheckBox_Experiencer.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        jCheckBox_Experiencer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_ExperiencerActionPerformed(evt);
            }
        });

        jCheckBox_Temporality.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jCheckBox_Temporality.setText("<html>Temporality<br><font color=\"gray\">Recent or historical</font></html>");
        jCheckBox_Temporality.setActionCommand("Concept and related relationship");
        jCheckBox_Temporality.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jCheckBox_Temporality.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        jCheckBox_Temporality.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_TemporalityActionPerformed(evt);
            }
        });

        jCheckBox_negation.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jCheckBox_negation.setText("<html>Assertion<br><font color=\"gray\">Affirmed, possible, or negated</font></html>");
        jCheckBox_negation.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
        jCheckBox_negation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox_negationActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckBox_Experiencer, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBox_Temporality, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBox_negation, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(811, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jCheckBox_Experiencer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBox_Temporality, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBox_negation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        jPanel_thirdlevel.add(jPanel7);

        jPanel5.add(jPanel_thirdlevel, java.awt.BorderLayout.NORTH);

        jPanel9.setBackground(new java.awt.Color(255, 255, 254));
        jPanel9.setLayout(new java.awt.GridLayout(1, 3));

        jPanel12.setBackground(new java.awt.Color(255, 255, 254));

        javax.swing.GroupLayout jPanel12Layout = new javax.swing.GroupLayout(jPanel12);
        jPanel12.setLayout(jPanel12Layout);
        jPanel12Layout.setHorizontalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1043, Short.MAX_VALUE)
        );
        jPanel12Layout.setVerticalGroup(
            jPanel12Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 168, Short.MAX_VALUE)
        );

        jPanel9.add(jPanel12);

        jPanel10.setBackground(new java.awt.Color(255, 255, 254));

        jButton2.setText("Start");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Set Output Directory");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 1010, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 1010, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel10Layout.createSequentialGroup()
                .addContainerGap(110, Short.MAX_VALUE)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel9.add(jPanel10);

        jPanel11.setBackground(new java.awt.Color(255, 255, 254));

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1043, Short.MAX_VALUE)
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 168, Short.MAX_VALUE)
        );

        jPanel9.add(jPanel11);

        jPanel5.add(jPanel9, java.awt.BorderLayout.SOUTH);

        add(jPanel5, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void jCheckBox_conceptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_conceptActionPerformed

        //this.jRadioButton_nlp_normal.setVisible(flag);
        //this.jRadioButton_nlp_quick.setVisible(flag);
}//GEN-LAST:event_jCheckBox_conceptActionPerformed
    /**paintpath() method is used to draw the path between steps
     * on screen;
     */
    private void paintpath(Graphics g)
    {
        // get the corner location 
        Point topleftpoint = jPanel8.getLocation();

        int f_width = this.getWidth();
        int f_height = this.getHeight();

        int height = jPanel8.getHeight();
        int width = f_width;

        // color = black
        g.setColor(Color.black);

        // draw line from start point to the middle of second level
        g.drawLine((int)(width/2), (int)(topleftpoint.getY() + 10),
                (int)(width/2), (int)(topleftpoint.getY() + height -10) );
        // draw arrows for this;
        int arrow2_x = (int)(width/2), arrow2_y = (int)(topleftpoint.getY() + height -10);
        g.drawLine(arrow2_x, arrow2_y, arrow2_x-5, arrow2_y-5);
        g.drawLine(arrow2_x, arrow2_y, arrow2_x+5, arrow2_y-5);

        // draw line from start point To the first rectangle on second level
        int x2=(int)(width/2)-10;
        int y2=(int)(topleftpoint.getY() + 10);
        int x1=(int)(width/6);
        int y1=(int)(topleftpoint.getY() + height -10);
        g.drawLine( x2, y2, x1, y1 );
        // draw arrow
        int triangle_long  = Math.abs(x1 - x2);
        int triangle_short = Math.abs(y2 - y1);
        double triangle_waist = Math.sqrt(triangle_long*triangle_long + triangle_short*triangle_short);
        int arrowlong = 5;
        double arrow_waist = Math.sqrt(arrowlong*arrowlong*2);
        int new_x=(int)(triangle_short*arrow_waist/triangle_waist)+x1;
        int new_y= y1 - (int)(triangle_long*arrow_waist/triangle_waist);
        g.drawLine(x1, y1, new_x, new_y);




        // draw line from start point To the third rectangle on second level
        int m2=(int)(width/2)+10;
        int n2=(int)(topleftpoint.getY() + 10);
        int m1=(int)(width*5/6);
        int n1=(int)(topleftpoint.getY() + height -10);
        g.drawLine( m2, n2, m1, n1 );
        // draw arrow
        int triangle_long2  = Math.abs(m1 - m2);
        int triangle_short2 = Math.abs(n2 - n1);
        double triangle_waist2 = Math.sqrt(triangle_long2*triangle_long2 + triangle_short2*triangle_short2);
        int arrowlong2 = 5;
        double arrow_waist2 = Math.sqrt(arrowlong2*arrowlong2*2);
        int new_m=(int)(triangle_short2*arrow_waist2/triangle_waist2)+m1;
        int new_n= n1 - (int)(triangle_long2*arrow_waist2/triangle_waist2);
        g.drawLine(m1, n1, new_m, new_n);



        Point thirdlevel_topleftCorner = jPanel5.getLocation();

        // draw the vectial line
        int arrow1_x = (width*7/12), arrow1_y = (int)(thirdlevel_topleftCorner.getY()+5);
        g.drawLine(arrow1_x, arrow1_y,
                   arrow1_x,
                (int)(thirdlevel_topleftCorner.getY() +  jPanel_thirdlevel.getHeight()/2 - 5));
        g.drawLine(
                arrow1_x,
                (int)(thirdlevel_topleftCorner.getY() +  jPanel_thirdlevel.getHeight()/2 - 5),
                (int)(width*2/3 - 10 ),
                (int)(thirdlevel_topleftCorner.getY() +  jPanel_thirdlevel.getHeight()*3/4 )
                );
        // draw arrow
        g.drawLine( arrow1_x, arrow1_y, arrow1_x-5, arrow1_y+5);
        g.drawLine( arrow1_x, arrow1_y, arrow1_x+5, arrow1_y+5);


        // jpanel9



        int y4=(int)((jPanel9.getLocation().getY())
                    + jPanel5.getLocation().getY()
                    + jPanel9.getHeight() - 80 );
        g.drawLine(
                (int)(width/2), arrow1_y,
                (int)(width/2), y4                );
        // draw arrow
        g.drawLine((int)(width/2), y4, (int)(width/2)-5, y4-5);
        g.drawLine((int)(width/2), y4, (int)(width/2)+5, y4-5);
    }

    /**paint() method is overrided here as we need to draw the path between steps
     * on screen;
     */
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        // paint path and arrows
        paintpath(g);
    }

    
    private void jCheckBox_PreDefiinedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_PreDefiinedActionPerformed

        jCheckBox_Dates.setEnabled(jCheckBox_PreDefiined.isSelected());
        jCheckBox_SSN.setEnabled(jCheckBox_PreDefiined.isSelected());
    }//GEN-LAST:event_jCheckBox_PreDefiinedActionPerformed

    private void jCheckBox_ExperiencerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_ExperiencerActionPerformed
        // TODO add your process code here:
}//GEN-LAST:event_jCheckBox_ExperiencerActionPerformed

    private void jCheckBox_TemporalityActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_TemporalityActionPerformed
        // TODO add your process code here:
}//GEN-LAST:event_jCheckBox_TemporalityActionPerformed

    private void jCheckBox_negationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox_negationActionPerformed
        // TODO add your process code here:
}//GEN-LAST:event_jCheckBox_negationActionPerformed



    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        __gui.show_dialog_of_preference_to_manage_dictionaries();


        
        
    }//GEN-LAST:event_jButton1ActionPerformed

    /**user click start button to apply setting and run the NLP assistant*/
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

        //##1##
        // ##<1>## stop the thread if thread is already running now
        
        //final boolean flag_need_to_find_dates;
        //final boolean FLAG_OUTPUT_NEGATED;

        //final boolean isThreeColumnFile;

        if (jCheckBox_concept.isSelected()) 
            env.Parameters.NLPAssistant.OUTPUTCONCEPT = true;
        else  
            env.Parameters.NLPAssistant.OUTPUTCONCEPT = false;

        // MUSTMUST need to be deleted later
        // flag_need_to_find_dates
        if (jCheckBox_Dates.isSelected()) 
            env.Parameters.NLPAssistant.Output_Dates = true;
        else env.Parameters.NLPAssistant.Output_Dates = false;

        

        if (jCheckBox_PreDefiined.isSelected()&&jCheckBox_SSN.isSelected() )
            env.Parameters.NLPAssistant.OUTPUTSSN = true;
        else 
            env.Parameters.NLPAssistant.OUTPUTSSN = false;

        if (jCheckBox_PreDefiined.isSelected()&&(jCheckBox_Dates.isSelected()))
            env.Parameters.NLPAssistant.OUTPUTDATE = true;
        else 
            env.Parameters.NLPAssistant.OUTPUTDATE = false;

        // check and set flag of custom regular expression
        if (jCheckBox_CustomRegex.isSelected()){ 
            env.Parameters.NLPAssistant.OUTPUTCUSTOMREGEX = true;
        }else 
            env.Parameters.NLPAssistant.OUTPUTCUSTOMREGEX = false;

        

        // check and set flag for quick NLP(term extraction)
        if ((jCheckBox_concept.isSelected())&&(this.jRadioButton_nlp_quick.isSelected())) {
            env.Parameters.NLPAssistant.QuickNLPEnabled = true;
        }else{ 
            env.Parameters.NLPAssistant.QuickNLPEnabled = false; }


        // check and set flag of temporality
        if ((!jRadioButton_nlp_quick.isSelected())&&(jCheckBox_Temporality.isSelected())){
            env.Parameters.NLPAssistant.OUTPUTTEMPORALITY = true;
        }else
            env.Parameters.NLPAssistant.OUTPUTTEMPORALITY = false;

        // check and set flag of experiencer
        if ((!jRadioButton_nlp_quick.isSelected())&&(jCheckBox_Experiencer.isSelected())){
            env.Parameters.NLPAssistant.OUTPUTEXPERIENCER = true;
        }else
            env.Parameters.NLPAssistant.OUTPUTEXPERIENCER = false;

        // mark flag to indicate whether we need to find and output negation terms
        if ((!jRadioButton_nlp_quick.isSelected())&&(jCheckBox_negation.isSelected())){
            //FLAG_OUTPUT_NEGATED = true;
            env.Parameters.NLPAssistant.OUTPUTNEGATION = true;
        }else{
            //FLAG_OUTPUT_NEGATED = false;
            env.Parameters.NLPAssistant.OUTPUTNEGATION = false;
        }

        //if (jCheckBox_complex_notes.isSelected()) {
        //    env.Parameters.COMPLEX_NOTES_FORMAT_IN_PTID_NOTEID_NOTES = "Yes";
        //isThreeColumnFile = false;
        //} else {
        //    env.Parameters.COMPLEX_NOTES_FORMAT_IN_PTID_NOTEID_NOTES = "No";
        //    isThreeColumnFile = false;
        //
        //}

        


        //##2## show another tab
        __gui.enterTab_createAnnotaion_step2();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jRadioButton_nlp_quickActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton_nlp_quickActionPerformed
        
    }//GEN-LAST:event_jRadioButton_nlp_quickActionPerformed

    private void jRadioButton_nlp_quickStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jRadioButton_nlp_quickStateChanged
        jCheckBox_Experiencer.setEnabled(!jRadioButton_nlp_quick.isSelected());
        jCheckBox_Temporality.setEnabled(!jRadioButton_nlp_quick.isSelected());
        jCheckBox_negation.setEnabled(!jRadioButton_nlp_quick.isSelected());
    }//GEN-LAST:event_jRadioButton_nlp_quickStateChanged

    protected enum fileInputType{
        importXMLandPin, selectClinicalTextFiles, setXmlOutputforConcepts
    };

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // select a folder as the xml output path
        JFileChooser jFileChooser1 = setFileChooserAttributes(fileInputType.setXmlOutputforConcepts);

        // show the dialog of file chooser
        int re = jFileChooser1.showDialog(this, "Set Output Directory");
        // record latest accessed folder
        recentlyOpennedFolder = jFileChooser1.getSelectedFile();

        // set the value of variable to record the selected path
        // if get valid return
        if (re == 0){
            String outputpath;
            //jFileChooser1.setFileSelectionMode(1);
            File f = jFileChooser1.getSelectedFile();

            if(!f.exists())
                outputpath = jFileChooser1.getCurrentDirectory().toString();
            else
                outputpath = f.getAbsolutePath();


            env.Parameters.NLPAssistant.outputpath = outputpath;

        }
    }//GEN-LAST:event_jButton3ActionPerformed


    private JFileChooser setFileChooserAttributes(fileInputType type){

            JFileChooser jFileChooser2 = new JFileChooser();
            jFileChooser2.setDialogType( JFileChooser.SAVE_DIALOG );
            jFileChooser2.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            jFileChooser2.setMultiSelectionEnabled(true);
            jFileChooser2.setDialogTitle("Select Directory to save XML results");
            //String[] all = new String[] { "" };
            //String[] xmlpin = new String[] { "pins", "xml" };

            int size = jFileChooser2.getChoosableFileFilters().length;
            javax.swing.filechooser.FileFilter[] filefilters = jFileChooser2.getChoosableFileFilters();

            for (int i = 0; i < filefilters.length; i++) {
               jFileChooser2.removeChoosableFileFilter(filefilters[i]);
            }


            //jFileChooser2.addChoosableFileFilter(new commons.SimpleFileFilter(all,
            //    "All files (*.*)"));
            //jFileChooser2.addChoosableFileFilter(new commons.SimpleFileFilter(xmlpin,
            //    "XML and PINS annotation files (*.xml, *.pins)"));

            // set dafault folder is latest accessed folder
            jFileChooser2.setCurrentDirectory( recentlyOpennedFolder );


            return jFileChooser2;



    }




    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JCheckBox jCheckBox_CustomRegex;
    private javax.swing.JCheckBox jCheckBox_Dates;
    private javax.swing.JCheckBox jCheckBox_Experiencer;
    private javax.swing.JCheckBox jCheckBox_PreDefiined;
    private javax.swing.JCheckBox jCheckBox_SSN;
    private javax.swing.JCheckBox jCheckBox_Temporality;
    private javax.swing.JCheckBox jCheckBox_concept;
    private javax.swing.JCheckBox jCheckBox_negation;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JPanel jPanel_firstlevel;
    private javax.swing.JPanel jPanel_secondlevel;
    private javax.swing.JPanel jPanel_thirdlevel;
    private javax.swing.JPanel jPanel_top;
    private javax.swing.JRadioButton jRadioButton_nlp_normal;
    private javax.swing.JRadioButton jRadioButton_nlp_quick;
    // End of variables declaration//GEN-END:variables

}
